package com.atguigu.jxc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.jxc.dao.DamageListGoodsDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.DamageListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * ClassName: DamageListGoodsServiceImpl
 * Description:
 * Date: 2022/1/16 18:14
 *
 * @version:
 * @since JDK 1.8
 */


@Service
public class DamageListGoodsServiceImpl implements DamageListGoodsService {



    @Autowired
    private DamageListGoodsDao damageListGoodsDao;

    @Override
    public void saveDamageListGoods(DamageList damageList, String damageListGoodsStr, HttpSession session) {

        User user = (User)session.getAttribute("currentUser");

        damageList.setUserId(user.getUserId());

        damageListGoodsDao.saveDamageList(damageList);

        List<DamageListGoods> goodsList = JSONObject.parseArray(damageListGoodsStr, DamageListGoods.class);

        for (DamageListGoods damageListGoods : goodsList) {
            damageListGoods.setDamageListId(damageList.getDamageListId());
            damageListGoodsDao.saveDamageGoods(damageListGoods);
        }
    }


    @Override
    public List<DamageList> getDamageListGoods(String sTime, String eTime) {
        List<DamageList> damageListList = damageListGoodsDao.getDamageListGoods(sTime,eTime);
        return damageListList;
    }


    @Override
    public List<DamageListGoods> getGoodsList(Integer damageListId) {
        List<DamageListGoods> damageListGoodsList = damageListGoodsDao.getGoodsList(damageListId);
        return damageListGoodsList;
    }
}
